package core;

/** 
 * @author Gianni Gambetti
 * @since April 5, 2009
 */
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class ByteIO {
	
	private static FileOutputStream fOut=null;
	
	public static void createOutputStream(String filename) throws FileNotFoundException{
		if(fOut != null){
			System.out.println("WARNING STREAM ALREADY CREATED!!!!");
		}
		fOut = new FileOutputStream(filename);
	}
	
	public static void write(byte[] b) throws IOException{
		fOut.write(b);
	}
	
	public static void closeOutputStream(){
		try {
			fOut.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		fOut=null;
	}
	
	private static FileInputStream fIn=null;
	
	public static void openInputStream(String filename) throws FileNotFoundException{
		fIn = new FileInputStream(filename);
	}
	
	
	public static byte[] read(int length) throws IOException{
		byte[] b = new byte[length];
		int i = fIn.read(b);
		if(i < 0){
			b = null;
		}
		return b;
	}
	
	public static void closeInputStream(){
		try {
			fIn.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		fIn=null;
	}
	
	
	

}
